package com.qwe.graduation.service.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.qwe.graduation.entity.MessageLeave;
import com.qwe.graduation.entity.vo.MessageLeaveVo;
import com.qwe.graduation.mapper.MessageLeaveMapper;
import com.qwe.graduation.service.IMessageLeaveService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 资讯留言表 服务实现类
 * </p>
 *
 * @author 林卓锋
 * @since 2023-01-19
 */
@Service
public class MessageLeaveServiceImpl extends ServiceImpl<MessageLeaveMapper, MessageLeave> implements IMessageLeaveService {

    @Autowired
    MessageLeaveMapper messageLeaveMapper;

    @Override
    public List<MessageLeaveVo> findList(String name,String headline,String module) {


        List<MessageLeaveVo> list = messageLeaveMapper.findList();
        List<MessageLeaveVo> list2 = list.stream().filter(message->  !StringUtils.isBlank(name)?message.getName().contains(name):true)
                .filter(message->  !StringUtils.isBlank(headline)?message.getHeadline().contains(headline):true)
                .filter(message->  !StringUtils.isBlank(module)?message.getModule().contains(module):true)
                .sorted((Comparator.comparing(MessageLeaveVo::getLeaveTime).reversed()))
                                        .collect(Collectors.toList());

        return list2;
    }
}
